package com.fei.jvmtest;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ClassLoaderTest {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        ClassLoader classLoader = new ClassLoader() {

            @Override
            public Class<?> loadClass(String name)
                    throws ClassNotFoundException {
                try {
                    InputStream is = new FileInputStream(new File("F:\\my\\maven-test\\target\\classes\\com\\fei\\jvmtest\\Interrupt.class"));

                    byte[] b = new byte[is.available()];
                    is.read(b);
                    
                    return defineClass(name, b, 0, b.length);
                }
                catch (IOException e) {
                    e.printStackTrace();
                    throw new ClassNotFoundException(name);
                }
            }

        };
        
        Object obj = classLoader.loadClass("ClassLoaderTest.java").newInstance();
        System.out.println(obj.getClass());
        
        
    }
}
